import { defineStore } from 'pinia';
import { getInputOption } from 'src/services/repairService';

export const useInputOption = defineStore('inputOptionStore', {
  state: () => ({
    data:{
      system:[] as string[],
      lv1:[],
      lv2:[],
      lv3:[],
      lv4:[] as string[],
      lv5:[] as string[],
      lv6:[],
      equipmentClass:[] as string[],
      equipmentClassLv4:[] as string[],
      equipmentClassLv5:[] as string[],
      workgroup:[]as string[],
      line:[]as string[],
      depot:[]as string[],
    },
    yearOptions: [] as string[],
  }),
  getters: {
  },
  actions: {
    async init(){
      const res = await getInputOption()
      console.log(res.data);
      this.data = res.data
      this.data.depot.unshift('----------')
      // this.data = {...this.data, 
      //   workgroup:['A','B','C','D','E','F','G','H','CEWS','FIT']
      // }
    },
    initYears(initYear: number){
      const cur_year  = new Date().getFullYear()
      console.log(cur_year);
      const max = cur_year - initYear
      let i = 0;
      while (i < max + 1) {
        this.yearOptions.push((initYear + i).toString());
        i++;
      }
    }
  },
});
